<template>
    <div>
        <city-header></city-header>
        <city-search :cities="cities"></city-search>
        <city-list :cities="cities"
                   :hotcities="hotCities"
                   :letter="letter"
        ></city-list>
        <alphabet :cities="cities"
                  @change="handleLetterChange"
        ></alphabet>
    </div>
</template>

<script>
import CityHeader from './components/CityHeader'
import CitySearch from './components/Search'
import CityList from './components/CityList'
import Alphabet from './components/alphabet'
import axios from 'axios'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    Alphabet
  },
  data () {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  mounted () {
    this.getCityInfo()
  },
  methods: {
    getCityInfo: function () {
      axios.get('/api/city.json').then(this.getCityInfoSucc)
    },
    getCityInfoSucc: function (res) {
      res = res.data
      if (res.ret && res.data) {
        this.cities = res.data.cities
        this.hotCities = res.data.hotCities
      }
    },
    handleLetterChange (letter) {
      this.letter = letter
    }
  }
}
</script>

<style scoped lang="stylus">

</style>
